package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.project.RCProjectMoney;
import com.shrct.businessprocess.purchase.RCBasePurchaseOrderAccept;
import com.shrct.businessprocess.purchase.RCBasePurchasePayRequest;
import com.shrct.businessprocess.purchase.RCPurchaseOrderAcceptPay;
import com.shrct.businessprocess.purchase.RCPurchaseOrderAcceptPayDAO;
import com.shrct.businessprocess.purchase.impl.RCPurchaseOrderAcceptPayImpl;
import com.uniquesoft.uidl.validation.Validates;
import edu.fudan.mylang.pf.BaseDAOService;
import edu.fudan.mylang.utils.DateUtil;
import java.util.Date;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.purchase.RCPurchaseOrderAcceptPayDAO")
public class RCPurchaseOrderAcceptPayDAOImpl extends BaseDAOService<RCPurchaseOrderAcceptPay> implements RCPurchaseOrderAcceptPayDAO {
  public RCPurchaseOrderAcceptPay create(final RCBasePurchaseOrderAccept accept, final RCBasePurchasePayRequest payRequest, final RCProjectMoney amount) {
    RCPurchaseOrderAcceptPay _xblockexpression = null;
    {
      RCProjectMoney _totalAmount = accept.getTotalAmount();
      Double _hostAmount = _totalAmount.toHostAmount();
      RCProjectMoney _totalPaidAmount = accept.getTotalPaidAmount();
      RCProjectMoney _plus = _totalPaidAmount.plus(amount);
      Double _hostAmount_1 = _plus.toHostAmount();
      boolean _greaterEqualsThan = (_hostAmount.compareTo(_hostAmount_1) >= 0);
      Validates.Assert(_greaterEqualsThan, "\u652F\u4ED8\u603B\u91D1\u989D\u4E0D\u5E94\u8BE5\u8D85\u51FA\u6536\u8D27\u91D1\u989D");
      payRequest.getRemainAmount();
      RCProjectMoney _remainAmount = payRequest.getRemainAmount();
      Double _hostAmount_2 = _remainAmount.toHostAmount();
      Double _hostAmount_3 = amount.toHostAmount();
      boolean _greaterEqualsThan_1 = (_hostAmount_2.compareTo(_hostAmount_3) >= 0);
      Validates.Assert(_greaterEqualsThan_1, "\u5206\u914D\u603B\u989D\u4E0D\u5E94\u8D85\u51FA\u4ED8\u6B3E\u7533\u8BF7\u603B\u989D\u5EA6");RCPurchaseOrderAcceptPay rCPurchaseOrderAcceptPay=RCPurchaseOrderAcceptPayImpl.create(getObjectFactory());
      final Procedure1<RCPurchaseOrderAcceptPay> _function = new Procedure1<RCPurchaseOrderAcceptPay>() {
          public void apply(final RCPurchaseOrderAcceptPay it) {
            it.setAmount(amount);
            it.setAccept(accept);
            it.setPay(payRequest);
            Date _day = DateUtil.today();
            it.setDate(_day);
          }
        };
      RCPurchaseOrderAcceptPay _doubleArrow = ObjectExtensions.<RCPurchaseOrderAcceptPay>operator_doubleArrow(rCPurchaseOrderAcceptPay, _function);
      _xblockexpression = (_doubleArrow);
    }
    return _xblockexpression;
  }
}
